package com.skyk.config;

import com.skyk.config.interceptor.SessionKeyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

//注册拦截器:
//配置拦截器使其生效

/*继承WebMvcConfigurerSupport接口，重写addInterceptor方法：
  目的是将自定义拦截器配置到系统配置项里，并设置合理的拦截路径*/
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
    @Autowired
    private SessionKeyInterceptor sessionKeyInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //开始注册自定义拦截器
        registry.addInterceptor(sessionKeyInterceptor)
                .addPathPatterns("/user/**")        //拦截所有请求
                .excludePathPatterns("/user/login"); //排除 /user/login
    }


}
